// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

const db = cloud.database();

// 插入database数据
exports.main = async (event, context) => {
  console.log(event);
  const todoCollection = db.collection('todo_list');
  return new Promise((resolve, reject) => {
    todoCollection
      .add({
        data: {
          content: event.content,
          mark: event.mark,
          is_done: false
        }
      })
      .then(rst => {
        console.log(rst);
        resolve(rst)
      })
      .catch(err => {
        console.log(err);
        reject(err);
      })
  })
}